<script>
export default {
	onLaunch: function() {
		const that = this;
		// #ifdef APP-PLUS   
		//必须是APP环境才有热更新的功能
		plus.runtime.getProperty(plus.runtime.appid, function(widgetInfo) {
			uni.request({
				url: that.$config.UPGRADE_CHECK_URL[process.env.NODE_ENV],
				data: {
					version: widgetInfo.version,
					name: widgetInfo.name
				},
				success: (result) => {
					var data = result.data;
					if (data.update && data.wgtUrl) {
						uni.downloadFile({
							url: data.wgtUrl,
							success: (downloadResult) => {
								if (downloadResult.statusCode === 200) {
									plus.runtime.install(downloadResult.tempFilePath, {
										force: false
									}, function() {
										console.log('install success...');
										plus.runtime.restart();
									}, function(e) {
										console.error('install fail...');
									});
								}
							}
						});
					}
				}
			});
		});
		//监听UniPush推送平台的数据
		setTimeout(function() {
			const _handlePush = function(message) {
				const existToken = uni.getStorageSync(that.$config.TOKEN_NAME);
				if (that.$util.isNotEmpty(existToken)) {
					if (message.payload.type === 'msg') { //如果是消息类型
						uni.navigateTo({
							url: '/pages/msg/show-msg?data=' + message.payload.id
						});
					}
				} else {
					uni.showToast({
						title: '尚未登录',
						duration: 1000
					});
				}
			};
			plus.push.addEventListener('click', _handlePush);
			//plus.push.addEventListener('receive', _handlePush);
			console.log('监听UniPush推送平台的数据！');
		}, 1000)
		
		//#endif
	},
	onShow: function() {
		console.log('App Show');
	},
	onHide: function() {
		console.log('App Hide');
	}
};
</script>

<style>
@import "./common/app.scss";
@import './common/uni.css';
/* 解决头条小程序组件内引入字体不生效的问题 */
/* #ifdef MP-TOUTIAO */
@font-face {
	font-family: uniicons;
	src: url('/static/uni.ttf');
}
/* #endif */

</style>